const mongoose = require('mongoose')
const bcrypt = require('bcrypt');
const url = "mongodb://101.132.154.15:27017";
mongoose.connect(url, { useNewUrlParser: true })
.then(() => {
console.log('连接成功')
})
.catch((err) => {
console.log('连接失败', err)
});

const UserSchema = new mongoose.Schema({
    username: {type:String,unique:true},
    password:{
        type:String,
        set(val){
            return bcrypt.hashSync(val,10)
        }
    },
    userword:{
        type:[{wordname:String,wordowner:String}],
        default:[{
            wordowner:1,
            wordname:1
        },{
            wordowner:2,
            wordname:1
        }]
    }
})
const WordSchema = new mongoose.Schema({
    wordname: {type:String},
    worddscript:{type:String},
    wordowner:{type:String},
    wordcontent:{type:String}
})
const User = mongoose.model('User',UserSchema)
const Word = mongoose.model('Word',WordSchema)
// User.db.dropCollection('users')
module.exports = {User,Word}